﻿Imports System.Data
Imports VSModel
Imports Cls_Common
Partial Class Control_Menu_HeaderMenuAdmin
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            If Session("UserName") Is Nothing Or Session("HuyenId") Is Nothing Then
                Dim retURL = Request.RawUrl
                Response.Redirect("~/Login.aspx?retURL=" & retURL)
            End If

            If Session("UserName") = "admin" Then
                Dim lstNode As New DataSet
                lstNode.ReadXml(MapPath("../../xml/HeaderMenuAdmin.xml"))
                With rptMenu
                    .DataSource = lstNode.Tables("Node")
                    .DataBind()
                End With
            End If
            'load list huyen tuong ung
            Using Data As New VSEntities

                Dim _UserId As Integer = Session("UserId")

                'set current Huyen
                Dim HuyenId As Integer = (From j In Data.UsersProvinces Where j.UserId = _UserId Select j.ProvinceId).FirstOrDefault

                Dim p = (From q In Data.Provinces Where q.Id = HuyenId Select q Order By q.Title).ToList
                With ddlHuyenId
                    .DataValueField = "Id"
                    .DataTextField = "Title"
                    .DataSource = p
                    .DataBind()
                End With

            End Using

            'ddlHuyenId.SelectedValue = Session("HuyenId")
            'curHuyenId = Session("HuyenId")
        End If
    End Sub
    Protected Sub rptMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptMenu.ItemDataBound
        Dim hplTitle As HyperLink
        hplTitle = e.Item.FindControl("hplTitle")

        'hplTitle.NavigateUrl = DomainURL & "Page/Default.aspx?DepID=" & e.Item.DataItem("DepID").ToString
        hplTitle.NavigateUrl = e.Item.DataItem("URL").ToString
        hplTitle.Text = e.Item.DataItem("Title")

    End Sub

    Protected Sub ddlLanguageId_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlHuyenId.SelectedIndexChanged
        ' Session("HuyenId") = ddlHuyenId.SelectedValue
        'Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri)
    End Sub


    Protected Sub lbtnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnExit.Click
        Session("UserName") = Nothing
        Session("RoleID") = Nothing
        Response.Redirect("~/Login.aspx")
    End Sub
    Protected Sub hplChangePassword_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles hplChangePassword.Init
        hplChangePassword.CssClass = "thickbox"
        hplChangePassword.NavigateUrl = "~/Page/ChangePassword.aspx?keepThis=true&TB_iframe=true&height=215&width=210&modal=true"
    End Sub

    Protected Sub lbtnUserProfile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbtnUserProfile.Click
        Response.Redirect("~/Page/Users/UserProfile.aspx?Username=" & Session("Username"))
    End Sub

    Protected Sub hplRoot_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles hplRoot.Init
        hplRoot.NavigateUrl = "~/Page/Logged.aspx"
    End Sub
End Class
